<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $userid 用户ID
 * @property int $room_id 房间ID
 * @property int $column_id 直播分类
 * @property int $assistant_userid 助理用户ID
 * @property int $live_status 直播状态 1-未开播 2-正在直播
 * @property int $last_live_time 上次直播时间
 * @property int $fans_count 粉丝数量
 * @property int $listorder 排序
 * @property-read null|User $user 
 * @property-read null|Live $live 
 * @property-read null|User $assistant 
 * @property-read null|LiveColumn $column 
 */
class UserModelAnchor extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'user_model_anchor';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'room_id', 'column_id', 'assistant_userid', 'live_status', 'last_live_time', 'fans_count', 'listorder'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'room_id' => 'integer', 'column_id' => 'integer', 'assistant_userid' => 'integer', 'live_status' => 'integer', 'last_live_time' => 'integer', 'fans_count' => 'integer', 'listorder' => 'integer'];

    public function user(){
        return $this->belongsTo(User::class, 'userid', 'id')->select(['id', 'username', 'nickname', 'avatar']);
    }

    public function live(){
        return $this->hasOne(Live::class, 'userid', 'userid');
    }

    public function assistant(){
        return $this->hasOne(User::class, 'id', 'assistant_userid')->select('id', 'nickname', 'username', 'avatar');
    }

    public function column(){
        return $this->hasOne(LiveColumn::class, 'id', 'column_id')->select(['id', 'title']);
    }
}
